# -*- python -*-
# ex: set syntax=python:

# This is a sample master.cfg designed to test buildrunner.

import sys

c = BuildmasterConfig = {}

####### BUILDSLAVES

# The 'slaves' list defines the set of recognized buildslaves. Each element is
# a BuildSlave object, specifying a unique slave name and password.  The same
# slave name and password must be configured on the slave.
from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave("example-slave", "pass")]

# 'slavePortnum' defines the TCP port to listen on for connections from slaves.
# This must match the value configured into the buildslaves (with their
# --master option)
c['slavePortnum'] = 9989

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.  Here we point to the buildbot clone of pyflakes.

from buildbot.changes.gitpoller import GitPoller
c['change_source'] = GitPoller(
        'git://github.com/buildbot/pyflakes.git',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300)

####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.
#  In this case, just kick off a 'runtests' build

from buildbot.schedulers.basic import SingleBranchScheduler
c['schedulers'] = []
c['schedulers'].append(SingleBranchScheduler(
                            name="all",
                            branch='master',
                            treeStableTimer=None,
                            builderNames=["runtests"]))

####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a
#  build: what steps, and which slaves can execute them.  Note that any
# particular build will only take place on one slave.

from buildbot.process.factory import BuildFactory
from buildbot.steps.shell import ShellCommand

# Note that we use sys.executable here, which we normally could not rely upon
# (since the slave's path may be different than the master's). However,
# since this file is only meant for unittests and that the commands are sure to
# be run on the same machine, it works here.
factory = BuildFactory()
factory.addStep(ShellCommand, command=[sys.executable, '-c',
    'import sys;sys.stdout.write("buildrunner should run this")'],
    name='run', brDoStepIf=True)
factory.addStep(ShellCommand, command=[sys.executable, '-c',
    'import sys;sys.stdout.write("buildrunner should not run this")'],
    name='donotrun', brDoStepIf=False)


c['builders'] = [
  {'name': 'runtests',
   'factory': factory,
   'slavenames': ['example-slave'],
  }
]

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

from buildbot.status import html
from buildbot.status.web import auth, authz
authz_cfg=authz.Authz(
    # change any of these to True to enable; see the manual for more
    # options
    gracefulShutdown = False,
    forceBuild = True, # use this to test your slave once it is set up
    forceAllBuilds = False,
    pingBuilder = False,
    stopBuild = False,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg))

####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot
# installation's html.WebStatus home page (linked to the
# 'titleURL') and is embedded in the title of the waterfall HTML page.

c['title'] = "Pyflakes"
c['titleURL'] = "http://divmod.org/trac/wiki/DivmodPyflakes"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.WebStatus page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://localhost:8010/"

####### DB URL

# This specifies what database buildbot uses to store change and scheduler
# state.  You can leave this at its default for all but the largest
# installations.
c['db_url'] = "sqlite:///state.sqlite"
c['properties'] = {}
c['properties']['mastername'] = 'buildrunner_sample'
